package com.cmii.sjw.department.control.jsc.controller;

import com.cmii.sjw.department.control.jsc.model.dto.RoleCockpitDTO;
import com.cmii.sjw.department.control.jsc.model.dto.RoleDTO;
import com.cmii.sjw.department.control.jsc.service.RoleCockpitService;
import com.cmii.sjw.department.control.jsc.util.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 角色指标权限管理控制器
 *
 * @Author lizheng
 * @Date 2025-05-13 周二 10:55
 * @Version 1.0
 */
@Slf4j
@RestController
@CrossOrigin
@RequestMapping("/sys/cockpit")
public class RoleCockpitController {

    @Autowired
    private  RoleCockpitService roleCockpitService;

    /**
     * 获取指定角色的 cockpit 指标列表
     */
    @GetMapping("/list")
    public Result listByRoleId(@RequestParam Long roleId) {
        return Result.success(roleCockpitService.getCockpitListByRole(roleId));
    }

    /**
     * 保存某个角色的 cockpit 指标权限
     */
    @PostMapping("/save")
    public Result saveRoleCockpit(@RequestBody RoleCockpitDTO roleCockpitDTO) {
        roleCockpitService.saveOrUpdateRoleCockpits(roleCockpitDTO.getRoleId(), roleCockpitDTO.getCockpitIds());
        return Result.success("保存成功");
    }

    /**
     * 删除某个角色的指定指标权限
     */
    @PostMapping("/delete")
    public Result deleteRoleCockpit(@RequestParam Long roleId) {
        roleCockpitService.deleteRoleCockpit(roleId);
        return Result.success("删除成功");
    }
}
